class Solution {
    public int strToInt(String str) {
        str = str.trim();
        boolean lang = false;
        int num = 0;
        if(str == null || str.length()==0) {
            return 0;
        }
        if(str.charAt(0) == '-') {
            lang = true;
        } else if(str.charAt(0) == '+') {
            lang = false;
        } else if(str.charAt(0) > '9' ||'0' > str.charAt(0) ) {
            return 0;
        } else {
            num = (int)(str.charAt(0)-'0');
        }
        for(int i = 1;i < str.length();i++) {
            char ss = str.charAt(i);
            if(ss > '9' || '0' > ss) {
                break;
            } else {
                int temp = num;
                num = num*10+(int)(ss-'0');
                if(num/10 != temp) {
                    return lang?-Integer.MIN_VALUE:Integer.MAX_VALUE;
                }
            }
        }
        return lang?-num:num;
    }
}